import { request } from '../request/index'

let timers = []
let allIds = []
const uid = wx.getStorageSync('userId')

const deleteWei = (ids) => {
  if(timers.length > 0) {
    timers.forEach(item => {
      clearTimeout(item)
    })
    timers = []
  }

  ids.forEach(ele => {
    allIds.push(ele)
  })

  let time = null
  if(allIds.length > 0) {
    allIds.forEach((element, index) => {
      time = setTimeout(async () => {
        const { data } = await request({
          url: `/read0/${uid}/${element}`,
          dataType: 'json'
        })
        console.log(data)
        allIds.splice(0, 1)
        clearTimeout(timers[0])
        timers.splice(0,1)
      }, 7001*index)
      timers.push(time)
    })
  }
}

export default deleteWei